﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>用户管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 人事管理 <span class="c-gray en">&gt;</span> 员工管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c"><!--  入职日期范围：
		<input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;"> -->
		<select id="dept_id_1" class="select select-option" style="width:200px; height:30px">
			<option value="">请选择一级部门</option>
		</select>
		<select id="dept_id_2" class="select select-option" style="width:200px; height:30px">
			<option value="">请选择二级部门</option>
		</select>
		<input type="text" class="input-text" style="width:250px" placeholder="输入员工编号/姓名" id="content" name="content">
		<button class="btn btn-success radius" id="query" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"> <a href="javascript:;" onclick="addMethod('添加用户','member-add.html','800','510')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加员工</a></span> <span class="r">共有数据：<strong>0</strong> 条</span> </div>
	<div class="mt-20">
	<table style="text-align:center;" class="table table-border table-bordered table-hover table-bg">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="80">编号</th>
				<th width="80">账号</th>
				<th width="100">姓名</th>
				<th width="100">性别</th>
				<th width="100">手机</th>
				<th width="100">邮箱</th>
				<th width="100">所属部门</th>
				<th width="100">加入时间</th>
				<th width="100">状态</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody></tbody>
	</table>
	</div>
	<div id="pageNum" class="text-c">
		<a id="first" class="btn btn-primary radius">首页</a>
		<a id="lastPage" class="btn btn-primary radius" >上一页</a>
		<span class="pageSpan"><label id="nowPage">0</label>/<label id="totalPage">0</label></span>
		<a id="nextPage" class="btn btn-primary radius">下一页</a>
		<a id="last" class="btn btn-primary radius">尾页</a>
	</div>
</div>
<script type="text/javascript" src="../MyJs/date_string.js"></script>
<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="../lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="../lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script> 
<script type="text/javascript">

	/*添加*/
    function addMethod(title,url,w,h){
        layer_show(title,url,w,h);
    }

	/*编辑*/
    function editMethod(id){
        layer_show("修改" , "member-add.html?id="+id , 800, 510 );
    }

	/*查看信息*/
	function showMember(id){
        layer_show("查看信息" , "member-show.html?id="+id , 600, 510 );
	}

	/*停用*/
	function member_stop(obj,id){
		layer.confirm('确认要停用吗？',function(index){
			$.post("/staffing/employee/closeOrOpen.do",{"id":id,"op":"close"},function(){});
			$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,id)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
			$(obj).remove();
			layer.msg('已停用!',{icon: 5,time:1000});
		});
	}

	/*启用*/
	function member_start(obj,id){
		layer.confirm('确认要启用吗？',function(index){
			$.post("/staffing/employee/closeOrOpen.do",{"id":id,"op":"open"},function(){});
			$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
			$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
			$(obj).remove();
			layer.msg('已启用!',{icon: 6,time:1000});
		});
	}

	$(function (){
		$(window).load(function(){
            getDeptList(-1,"dept_id_1");
			getListByPage(1);
		});

        //部门联动下拉框
        $("#dept_id_1").change(function(){
            var dept_id = $("#dept_id_1").val();
            getDeptList(dept_id,"dept_id_2");
        });

		//搜索
		$("#query").click(function(){
			getListByPage(1);
		});

		//首页
		$("#first").click(function(){
			getListByPage(1);
		});
		//尾页
		$("#last").click(function(){
			var total_page = parseInt($("#totalPage").html());
			getListByPage(total_page);
		});
		//上一页
		$("#lastPage").click(function(){
			var now_page = parseInt($("#nowPage").html());
			getListByPage(now_page <= 1 ? 1 : now_page - 1);
		});
		//下一页
		$("#nextPage").click(function(){
			var now_page = parseInt($("#nowPage").html());
			var total_page = parseInt($("#totalPage").html());
			getListByPage(now_page + 1 > total_page ? total_page : now_page + 1);
		});

		//分页显示所有用户
		function getListByPage(pageNum){
			var content = $("#content").val();
			var dept_id_1 = $("#dept_id_1").val();
			var dept_id_2 = $("#dept_id_2").val();
			var dept_id = "";
			if(dept_id_1 != null && dept_id_1 != ""){
                dept_id = dept_id_1;
			}
			if(dept_id_2 != null && dept_id_2 != "") {
                dept_id = dept_id_2;
			}
			$.post("/staffing/employee/getEmployeePage.do", {"current":pageNum, "size":5,"content":content,"dept_id":dept_id}, function(data) {
				$("table > tbody > tr").remove();
				$("strong").html(data.total);
				$("#nowPage").html(data.current);
				$("#totalPage").html(data.pages);
				$(data.records).each(function(i,v) {
					var content = "<tr class='text-c'>"
					content += "<td><input type='checkbox' value=''></td>"
					content += "<td>"+(i+1)+"</td>"
					content += "<td>"+v.emp_account+"</td>"
					content += '<td><a onClick="showMember('+ v.emp_id +')" href="javascript:;" title="查看信息">'+v.emp_name +'</a></td>'
					content += "<td>"+v.emp_sex+"</td>"
					content += "<td>"+v.emp_phone+"</td>"
					content += "<td>"+v.emp_email+"</td>"
					content += "<td>"+v.dept_name+"</td>"
					content += "<td>"+v.emp_in_date+"</td>"
					if(v.emp_state == 0){
						content += "<td class='td-status'><span class=\"label label-defaunt radius\">已停用</span></td>"
						content += '<td class="td-manage">' +
							'<a style="text-decoration:none" onClick="member_start(this,'+ v.emp_id +')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>' +
                            '<a title="编辑" href="javascript:;" onclick="editMethod(' + v.emp_id + ')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>' +
							'</td>'
					}else{
						content += "<td class='td-status'><span class='label label-success radius'>已启用</span></td>"
						content += '<td class="td-manage">' +
							'<a style="text-decoration:none" onClick="member_stop(this,'+ v.emp_id +')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>' +
                            '<a title="编辑" href="javascript:;" onclick="editMethod(' + v.emp_id + ')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>' +
							'</td>'
					}
					content += "</tr>"
					$("table > tbody").append(content);
				});
			},"json");
		}

        //加载部门
        function getDeptList(pid,select_id){
            if(select_id === "dept_id_2"){
                $("#"+select_id).empty();
                $("#"+select_id).append("<option value=''>请选择二级部门</option>");
			}
            $.post("/staffing/department/getDepartmentList.do", {"pid":pid} , function(data) {
                $(data).each(function(i,v) {
                    var content = "<option value="+v.dept_id+">"+v.dept_name+"</option>";
                    $("#"+select_id).append(content);
                });
            },"json");
        }

	});
</script>
</body>
</html>